$(function () {
   $('.highlight-btn').click(function (event) {
       event.preventDefault();
       var self = $(this);
       var tr = self.parent().parent();
       var post_id = tr.attr('data-id');
       var highlight = parseInt(tr.attr('data-highlight'));
       var url = '';
       if(highlight){
           url = '/cms/uhpost/';
       }else {
           url = '/cms/hpost/'
       }
       zlajax.post({
           'url':url,
           'data':{
               'post_id':post_id
           },
           'success':function (data) {
               if(data['code'] == 200){
                   xtalert.alertSuccessToast('操作成功！');
                   setTimeout(function () {
                       window.location.reload()
                   },500)
               }else{
                   console.log(post_id)
                   xtalert.alertInfo(data['message'])
               }
           },
           'fail':function (error) {
               xtalert.alertNetworkError()
           }
       })
   })
});
//帖子加火，去火
$(function () {
    $('.fire-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var tr = self.parent().parent();
        var post_id = tr.attr('data-id');
        var firelag = parseInt(tr.attr('data-firelag'));
        var url = '';

        if(firelag){
            url = '/cms/ufpost/'
        }else{
            url = '/cms/fpost/'
        }

        zlajax.post({
            'url':url,
            'data':{
                'post_id':post_id
            },
            'success':function (data) {
                if(data['code'] == 200){
                    xtalert.alertSuccessToast('操作成功');
                    setTimeout(function () {
                        window.location.reload()
                    },500)
                }else{
                    xtalert.alertInfo(data['message'])
                }
            }
        })
    })
})

$(function () {
   $('.del-post').click(function (event) {
       event.preventDefault();
       var self = $(this);
       var tr = self.parent().parent();
       var post_id = tr.attr('data-id');
       xtalert.alertConfirm({
           'title':'确认要删除这篇帖子吗？',
           'confirmText':'确认删除',
           'cancelText':'再想一想',
           'confirmCallback':function () {
               zlajax.post({
                   'url':'/cms/dpost/',
                   'data':{
                       'post_id':post_id
                   },
                   'success':function (data) {
                       if(data['code'] == 200){
                           window.location.reload()
                       }else {
                           xtalert.alertInfo(data['message'])
                       }
                   }
               })
           }
       })
   })
});